package com.iot.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.iot.domain.Light;
import com.iot.service.LightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wlr
 * @since 2022-01-05
 */
@RestController
@RequestMapping("/light")
public class LightController {
    @Autowired
    LightService lightService;
    @RequestMapping("/getLight")
    public Double getCurrentLight(){
        QueryWrapper<Light> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("time");
        wrapper.last("limit 1");
        List<Light> light = lightService.selectList(wrapper);
        if (light.size()!=0){
            Light light1 = light.get(0);
            return light1.getValue();
        }
        return 200.5;

    }
}

